//调用md5.js
let md5 = require("@/common/js/md5.js")
//懒得朋友可以下载：https://download.csdn.net/download/qvyyid/10673368
var app_secret = "YAYAPI";
var UNITS = {
	'年': 31557600000,
	'月': 2629800000,
	'天': 86400000,
	'小时': 3600000,
	'分钟': 60000,
	'秒': 1000
};
//获取当前时间戳
function getTimestamp() {
	//return(Date.parse(new Date()) / 1000).toString();
	var date = new Date()
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	var day = date.getDate();
	var hour = date.getHours();
	var minute = date.getMinutes();
	var second = date.getSeconds();
	var time = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
	return time;
};
//获取sign签名 
function getSign(keyOptions) {
	var data = keyOptions;
	delete data.sign;
	var str = "";
	var arr = [];
	var v = 0;
	for (var key in data) {
		arr[v] = key;
		v++;
	};
	arr.sort();
	for (var i = 0; i < arr.length; i++) {
		var key = arr[i];
		if(data[key]!="") str += "&" + key + "=" + data[key];
	};
	str = app_secret + str
	return md5(str);
};

//获取发送de数据
function getData(options) {
	if (options == '') {
		options = {};
	}
	// options.timestamp = getTimestamp();
	// var timestamp = getTimestamp();
	var sign = getSign(options).toLowerCase();
	var data = {
		sign: sign,
	};
	for (var key in data) {
		options[key] = data[key];
	};
	return options;
};
module.exports = {
	getData: getData
}
